package com.explorati.tree.LeetCode235.BinarySearchTree;

import com.explorati.tree.LeetCode235.BinarySearchTree.Solution.TreeNode;

public class Solution1 {

	public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
		assert p != null && q != null;
		if (root == null) {
			return null;
		}
		if (p.val < root.val && q.val < root.val) {
			lowestCommonAncestor(root.left, p, q);
		}
		if (p.val > root.val && q.val > root.val) {
			lowestCommonAncestor(root.right, p, q);
		}
		return root;
	}
}
